package com.cap12.processor;

import com.cap12.bean.Moon;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.*;
import org.springframework.stereotype.Component;

@Component
public class JamesBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        System.out.println("BeanDefinitionRegistryPostProcessor..postProcessBeanDefinitionRegistry(),Bean的数量 " + registry.getBeanDefinitionCount());
        //RootBeanDefinition rdb = new RootBeanDefinition(Moon.class);
        AbstractBeanDefinition rdb = BeanDefinitionBuilder.rootBeanDefinition(Moon.class).getBeanDefinition();
        registry.registerBeanDefinition("hello", rdb);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("BeanDefinitionRegistryPostProcessor..postProcessBeanFactory(),Bean的数量 " + beanFactory.getBeanDefinitionCount());
    }
}
